import 'dart:io';

import 'package:dio/dio.dart';
import 'package:my_photos/logging.dart';

import '../constants.dart';

int kConnectTimeout = 15000;

class NetworkClient {
  static const apiEndpoint = String.fromEnvironment(
    "endpoint",
    defaultValue: kDefaultProductionEndpoint,
  );

  late Dio _dio;

  Future<void> init() async {
    Logging.instance.$("doing the init");
    _dio = Dio(
      BaseOptions(
        connectTimeout: kConnectTimeout,
        headers: {
          HttpHeaders.userAgentHeader:
              'Mozilla/5.0 (Linux; Android 4.2.1; M040 Build/JOP40D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.59 Mobile Safari/537.36',
          'X-Client-Version': '1.0.0',
          'X-Client-Package': 'com.example.my_photos',
        },
      ),
    );
    Logging.instance.$("finish the init");
  }

  NetworkClient._privateConstructor();

  static NetworkClient instance = NetworkClient._privateConstructor();

  Dio getDio() => _dio;
}
